package scoreCard.LivestockJudging3C;

import java.util.List;

import scoreCard.LivestockJudging3C.R;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class FileArrayAdapter extends ArrayAdapter<Option>{

	private Context c;
	private int id;
	private List<Option>items;
	
	public FileArrayAdapter(Context context, int textViewResourceId,
			List<Option> objects) {
		super(context, textViewResourceId, objects);
		c = context;
		id = textViewResourceId;
		items = objects;
	}
	public Option getItem(int i)
	 {
		 return items.get(i);
	 }
	 @Override
       public View getView(int position, View convertView, ViewGroup parent) {
         View v = convertView;
         LayoutInflater vi;
         if (v == null) {
        	 vi = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        	 v = vi.inflate(id, null);
         }
 		
         final Option o = items.get(position);
         if (o != null) {
             ImageView imageView = (ImageView) v.findViewById(R.id.icon);
        	 TextView t1 = (TextView) v.findViewById(R.id.TextView01);
             TextView t2 = (TextView) v.findViewById(R.id.TextView02);
             
             // Set Text
             if(t1!=null) {
            	 t1.setText(o.getName()); 
             }
             if(t2!=null) {
                 t2.setText(o.getData()); 
             } 
             
             // Set Icon
             if (o.getData().equalsIgnoreCase("Competitions") || o.getData().contains("Back to") || o.getData().equalsIgnoreCase("Class")){
            	 imageView.setImageResource(R.drawable.folder);
             } else if (o.getData().contains(".3gp") || o.getName().contains("Recording")) {
            	 imageView.setImageResource(R.drawable.music);
             } else if ((o.getName().contains("Score") && !o.getName().contains("Total Score")) || o.getName().contains("Keep")) {
            	 imageView.setImageResource(R.drawable.score);
             } else if(o.getName().contains("Total Score")){
            	 imageView.setImageResource(R.drawable.medal);
             }
         }
         return v;
       }

}
